<template>
  <div class="dashboard-container Simulation-addition">
  <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
    <!-- 选择分类 -->
    <el-row :gutter="20" class="choice-classification">
      <el-col :span="12" :offset="6" class="choice-classification-top">
        <el-form-item label="选择分类：" prop="region" style="width: 100%;">
          <el-col :span="8">
            <el-select v-model="ruleForm.region" placeholder="一级分类">
              <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option>
            </el-select>
          </el-col>
          <el-col :span="8">
           <el-select v-model="ruleForm.region" placeholder="二级分类">
             <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option>
           </el-select>
          </el-col>
          <el-col :span="8">
            <el-select v-model="ruleForm.region" placeholder="三级分类">
              <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option>
            </el-select>
          </el-col>
        </el-form-item>
      </el-col>
    </el-row>

    <!-- 标题 -->
    <el-row :gutter="20">
      <el-col :span="12" :offset="6">
       <div class="grid-content bg-purple-dark title">
         <el-form-item label="标题：" prop="name" style="width: 100%;">
           <el-input v-model="ruleForm.name" placeholder="请输入标题"></el-input>
         </el-form-item>
       </div>
      </el-col>
    </el-row>

    <!-- 分值 -->
    <el-row :gutter="20">
      <el-col :span="12" :offset="6">
       <div class="grid-content bg-purple-dark title">
         <el-form-item label="分值：" prop="name" style="width: 100%;">
           <el-input v-model="ruleForm.name" placeholder="请输入本题分值"></el-input>
         </el-form-item>
       </div>
      </el-col>
    </el-row>

    <!-- 资料上传 -->
    <el-row :gutter="20">
      <el-col :span="12" :offset="6">
        <el-upload
          action="https://jsonplaceholder.typicode.com/posts/"
          list-type="picture-card"
          :on-preview="handlePictureCardPreview"
          :on-remove="handleRemove" style="margin-left: 105px;">
          <i class="el-icon-plus"></i>
        </el-upload>
        <el-dialog :visible.sync="dialogVisible">
          <img width="100%" :src="dialogImageUrl" alt="">
        </el-dialog>
      </el-col>
    </el-row>

    <!-- 添加 -->
    <el-row class="add-to" style="margin-top: 20px;">
      <el-row :gutter="20">
        <el-col :span="12" :offset="6">
          <div class="grid-content bg-purple" style="display: flex;">
            <el-button type="primary" style="margin-left: 13%; width: 100%;" @click="submitForm('ruleForm')">添加</el-button>
          </div>
        </el-col>
      </el-row>
    </el-row>
    </el-form>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        options: [{
          value: '选项1',
          label: '黄金糕'
        }, {
          value: '选项2',
          label: '双皮奶'
        }, {
          value: '选项3',
          label: '蚵仔煎'
        }, {
          value: '选项4',
          label: '龙须面'
        }, {
          value: '选项5',
          label: '北京烤鸭'
        }],
        ruleForm: {
          name: '',
          region: '',
          date1: '',
          date2: '',
          delivery: false,
          type: [],
          resource: '',
          desc: ''
        },
        rules: {
          name: [
            { required: true, message: '请输入活动名称', trigger: 'blur' },
            { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
          ],
          region: [
            { required: true, message: '请选择活动区域', trigger: 'change' }
          ],
          date1: [
            { type: 'date', required: true, message: '请选择日期', trigger: 'change' }
          ],
          date2: [
            { type: 'date', required: true, message: '请选择时间', trigger: 'change' }
          ],
          type: [
            { type: 'array', required: true, message: '请至少选择一个活动性质', trigger: 'change' }
          ],
          resource: [
            { required: true, message: '请选择活动资源', trigger: 'change' }
          ],
          desc: [
            { required: true, message: '请填写活动形式', trigger: 'blur' }
          ]
        },
        value: '',
        input: '',
        dialogImageUrl: '',
        dialogVisible: false
      }
    },
    computed: {

    },
    mounted() {

    },
    filters: {

    },
    methods: {
      handleRemove(file, fileList) {
        console.log(file, fileList);
      },
      handlePictureCardPreview(file) {
        this.dialogImageUrl = file.url;
        this.dialogVisible = true;
      },
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            alert('submit!');
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
  }
</script>
<style scoped>
  .choice-classification /deep/ .el-form-item__content{display: flex;}
</style>
<style>
  .Simulation-addition .choice-classification-top{display: flex;}
  .Simulation-addition .choice-classification-top .el-select{width: 100%;}
  .Simulation-addition .choice-classification-top .el-col-8{padding: 0px !important;}
  .Simulation-addition .choice-classification-top .el-col-8:nth-child(3){margin: 0px 10px;}
  .Simulation-addition .Question-type-data-top,.Simulation-addition .Question-type-data-bottom{display: flex;}
  .Simulation-addition .Question-type-data-top .el-col-12:nth-child(1),.Simulation-addition .Question-type-data-bottom .el-col-12:nth-child(1){margin-right: 10px;}
  .Simulation-addition .Question-type-data{width: 100%;margin-bottom: 10px;padding: 10px; background-color: #ececec;position: relative;}
  .Simulation-addition .Question-type-data:nth-last-child(1){margin-bottom: 0px;}
  .Simulation-addition .Question-type-data-auto{margin: 10px 0px;}
  .Simulation-addition .Question-type-data .increase{position: absolute; right: -60px; top: 60px;}
</style>
